home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
C/C++ Users Group Library 1996 July
/
C-C++ Users Group Library July 1996.iso
/
listings
/
v_10_08
/
1008085a
< prev
next >
Wrap
Text File
|
1991-12-02
|
812b
|
47 lines
// main1.cpp
// a quick test of RefCntPtr
#define DEBUG
#include "anyclass.hpp"
void main (void)
{
RefCntPtr(anyClass) ptr1;
// should evaluate to false,
// not execute show
if (ptr1)
ptr1->show();
ptr1 = new anyClass;
if (!ptr1)
cout << "new failed\n";
ptr1->intVal = 17;
ptr1->string =
"I wanna go to Australia, too";
// another access method
(*ptr1).show();
RefCntPtr(anyClass) ptr2 = ptr1;
ptr2->show();
ptr1 = 0;
// this one is an error
ptr1->show();
ptr2->show();
// previous anyClass will be deleted
ptr2 = new anyClass;
ptr2->intVal = 1234;
ptr2->string =
"Kansas? Why?";
// ptr2 destructor will be called here,
// at end of function, resulting
// in call to anyClass destructor
};